import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import call_service from '@dfeidao/atom-nodejs/msg/call-service';
import nodejs from '@dfeidao/atom-nodejs/msg/nodejs';
import render from '@dfeidao/atom-nodejs/render/render';
import { spaceid } from '../../atom/config';
export interface T {
	_id: string;
	menu_no: string;
	menu_name: string;
	client_type: string;
	parent_no: string;
	icon: string;
	show_type: string;
	description: string;
	priority: number;
	is_single: boolean;
	is_show: boolean;
	is_offline: boolean;
	is_guest: boolean;
	productid: string;
	systemid: string;
	formid: string;
	background: string;
	refsystemid: string;
	formname: string;
	package_no: string;
	package_name: string;
	package_url: string;
	auth_code: number;
	// c: [];
	c: T[];
}
export default async function na001(fd: IFeidaoAiNodejsComponent) {
	const user = await nodejs(fd.data.actionid, fd.data.sessionid, 'atom/s001', {}) as { productid: string };
	const menu = await call_service(fd.data.actionid, fd.data.sessionid, 'permservice.smartsecurity.getuserroleandauthinfo',
		{ systemid: '12', spaceid, 'productid': user.productid, 'clienttype': '3' }) as { menus: [] };
	const datas = menu.menus as T[];
	const t = (p: string) => {
		return datas.filter((d: { parent_no: string }) => {
			return d.parent_no === p;
		});
	};
	const d1 = datas.filter((d) => {
		d.c = t(d.menu_no);
		return d.parent_no === '';
	});
	let r = ``;
	const t1 = (data: T[], level: number) => {
		data.forEach((d) => {
			if (d.is_show) {
				if (d.c.length === 0) {
					let str = ``;
					str = `<div name="div` + level + `" class="menu` + level + `" style="display: none;">
	<div name="xz" class="bg " flag="0" data-feidao-l="` + level + `"
		data-feidao-actions="click:a002,mouseout:a003,mouseover:a004">
		<a href="` + (d.package_url ? d.package_url : 'javascript:void(0)') + `" class="color-f">
			<div class="opacity "
				style="height: 35px;line-height:35px;width: 100%;padding-left:30px;background-color: #5296FB;box-sizing: border-box; padding-right:5 px;padding-left: 17px;">
				<i class="iconfont ` + d.icon + ` font18 text-r display-ib"
					style="width: 35px;height:28px;line-height:28px;padding-right:15px;"></i>
				<span class="menu` + level + `_name font12 display-ib text-c" style="height: 28px;line-height: 28px;">`
						+ d.menu_name + `</span>
			</div>
		</a>
	</div>
</div>`;
					r += str;
				} else {
					let str = ``;
					str = `<div name="div` + level + `" class="menu` + level + `" style="display: none;">
	<div name="xz" class="bg" flag="0" data-feidao-l="` + level + `"
		data-feidao-actions="click:a002,mouseout:a003,mouseover:a004">
		<a href="` + (d.package_url ? d.package_url : 'javascript:void(0)') + `" class="color-f">
			<div class="opacity " style="height: 35px;line-height:35px;width: 100%;padding-right: 5px;padding-left: 10px;">
				<i  class="pr1 iconfont ` + d.icon + ` font12 text-r display-ib"
					style="width: 40px;height:28px;line-height:28px;"></i>
				<span class="menu` + level + `_name font12 display-ib text-c"
					style="height: 28px;line-height: 28px;width: 70px;">`
						+ d.menu_name + `</span>
					<i data-feidao-id="icon" class="pr1 iconfont icon-jiantouxia font12 text-r display-ib"
					style="width: 40px;height:28px;line-height:28px;"></i>
			</div>
		</a>
	</div>
	<div data-feidao-level="` + (level + 1) + `">`;
					r += str;
					t1(d.c, (level + 1));
				}
			}
		});
		r += `</div>
</div>`;
	};
	// 第一级目录
	d1.forEach((d) => {
		if (d.is_show) {
			if (d.c.length === 0) {
				r += `<div data-feidao-level="1">
	<div class="menu1 bg" style="height:40px;line-height: 40px;" flag="0" data-feidao-l="1"
		data-feidao-actions="click:a002,mouseout:a003,mouseover:a004">
		<a data-feidao-a="1" href="` + (d.package_url ? d.package_url : 'javascript:void(0)') + `" class="color-f">
			<span class="display-ib text-c vertical-a-m" style="width: 20px;height:40px;padding-right: 20px;padding-left: 10px;">
				<i class="font22 iconfont icon ` + d.icon + `" style="width: 44px;height:40px;" />
			</span>
			<span class="display-ib vertical-a-m font14" style="width: 100px;height: 40px;">` + d.menu_name + `</span>

	</div>`;
			} else {
				r += `<div data-feidao-level="1">
		<div class="menu1 bg" style="height:40px;line-height: 40px;" flag="0" data-feidao-l="1"
			data-feidao-actions="click:a002,mouseout:a003,mouseover:a004">
			<span class="display-ib text-c vertical-a-m" style="width: 20px;height:40px;padding-right: 15px;padding-left: 10px;">
				<i class="font22 iconfont icon ` + d.icon + `" style="width: 44px;height:40px;"></i>
			</span>
			<span class="display-ib vertical-a-m font14" style="width: 100px;height: 40px;padding-right: 5px;padding-left: 10px;">` + d.menu_name + `</span>
			<i class="iconfont cursor-p icon-down  font14 display-ib text-c" style="width:30px;"
				data-feidao-id="icon"></i>
		</div>
		<div data-feidao-level="2">`;
				t1(d.c, 2);
			}
		}
		r += '</div>';
	});
	render(fd.data.node, '', r, 'P01');
}
